package io.github.yotta.logger.manager.controller;

import io.github.yotta.common.api.model.Paging;
import io.github.yotta.logger.api.model.LogOperationData;
import io.github.yotta.logger.api.request.LogCreateRequest;
import io.github.yotta.logger.api.request.LogPageQueryRequest;
import io.github.yotta.logger.manager.controller.tenant.TenantIdLoader;
import io.github.yotta.logger.manager.service.LogService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yotta
 * @date 2023/3/26 18:20
 */
@RestController
@RequestMapping("/log/admin")
public class LogController {

    private final LogService logService;

    private final TenantIdLoader tenantIdLoader;

    public LogController(LogService logService, TenantIdLoader tenantIdLoader) {
        this.logService = logService;
        this.tenantIdLoader = tenantIdLoader;
    }

    @GetMapping("page")
    public Paging<LogOperationData> paging(LogPageQueryRequest request) {
        request.setTenantId(tenantIdLoader.getTenantId());
        return logService.page(request);
    }

    @GetMapping("list")
    public List<LogOperationData> list(LogPageQueryRequest request) {
        request.setTenantId(tenantIdLoader.getTenantId());
        return logService.list(request);
    }


    @PostMapping("save")
    public Long add(@RequestBody LogCreateRequest request) {
        return logService.save(request);
    }

}
